import RenderIf from "@/components/RenderIf";
import { Alert, AppShell, NavLink, Stack, Text } from "@mantine/core";
import {
  IconBugOff,
  IconCertificate,
  IconDatabaseDollar,
  IconFileDatabase,
  IconMenuDeep,
  IconPill,
  IconScript,
  IconScriptX,
  IconSettings,
  IconStars,
  IconStethoscope,
  IconUsers,
  IconUserScan,
} from "@tabler/icons-react";

import { useSessionStorage } from "@mantine/hooks";
import When from "./When";

function WithwingsNavbar() {
  const openPageTab = (v) => {
    location.href = v;
  };
  const [showDebugMenu] = useSessionStorage({
    key: "show-debug-menu",
    defaultValue: false,
  });
  return (
    <AppShell.Navbar p="md">
      <Stack
        justify="space-between"
        gap="xs"
        styles={{ root: { height: "100%" } }}
      >
        <div>
          <NavLink
            label="商品管理"
            leftSection={<IconStars size="1rem" stroke={1.5} />}
            childrenOffset={28}
          >
            <NavLink
              label="商品列表"
              leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
              onClick={() => openPageTab("/products")}
              childrenOffset={28}
            ></NavLink>
            <RenderIf auth="ProductRelated">
              <NavLink
                label="轮播图管理"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/carousel")}
                childrenOffset={28}
              ></NavLink>

              <NavLink
                label="活动卡片管理"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/activityCard")}
                childrenOffset={28}
              ></NavLink>
            </RenderIf>
            <NavLink
              label="库存变动"
              leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
              onClick={() => openPageTab("/stock/operations")}
            />
          </NavLink>
          <NavLink
            label="预付货款变动"
            leftSection={<IconDatabaseDollar size="1rem" stroke={1.5} />}
            onClick={() => openPageTab("/prepaid/operations")}
            childrenOffset={28}
          />
          <NavLink
            label="订单查询"
            leftSection={<IconScript size="1rem" stroke={1.5} />}
            onClick={() => openPageTab("/orders")}
            childrenOffset={28}
          ></NavLink>
          <NavLink
            label="售后管理"
            leftSection={<IconScriptX size="1rem" stroke={1.5} />}
            onClick={() => openPageTab("/afterSales")}
            childrenOffset={28}
          ></NavLink>
          <RenderIf auth="NonPartyAUserManagement">
            <NavLink
              label="商家&顾客"
              leftSection={<IconUsers size="1rem" stroke={1.5} />}
              childrenOffset={28}
            >
              <NavLink
                label="顾客管理"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/AG_CSR/users")}
                childrenOffset={28}
              />
              <NavLink
                label="店铺管理"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/AG_SHOP/users")}
                childrenOffset={28}
              />
              <NavLink
                label="批发商管理"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/AG_WHS/users")}
                childrenOffset={28}
              />
              <NavLink
                label="代理商管理"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/AG_AGENT/users")}
                childrenOffset={28}
              />
              <NavLink
                label="业务经理管理"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/MANAGER/users")}
                childrenOffset={28}
              />
              <NavLink
                label="总监管理"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/AG_DIRECTOR/users")}
                childrenOffset={28}
              />
              <NavLink
                label="董事管理"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/AU_DIRECTOR/users")}
                childrenOffset={28}
              />
            </NavLink>
          </RenderIf>
          <RenderIf auth="PartyAUserManagement">
            <NavLink
              label="内部人员管理"
              leftSection={<IconUserScan size="1rem" stroke={1.5} />}
              onClick={() => openPageTab("/PARTY_A/users")}
              childrenOffset={28}
            />
          </RenderIf>
          <RenderIf auth="QualificationApproval">
            <NavLink
              label="运营资格审批"
              leftSection={<IconCertificate size="1rem" stroke={1.5} />}
              childrenOffset={28}
            >
              <NavLink
                label="开店申请"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/AG_SHOP/applications")}
                childrenOffset={28}
              />
              <NavLink
                label="批发商申请"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/AG_WHS/applications")}
                childrenOffset={28}
              />
              <NavLink
                label="代理商申请"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/AG_AGENT/applications")}
                childrenOffset={28}
              />
              <NavLink
                label="经理申请"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/MANAGER/applications")}
                childrenOffset={28}
              />
            </NavLink>
          </RenderIf>
          <RenderIf auth="ProductConsult">
            <NavLink
              label="商品咨询"
              leftSection={<IconPill size="1rem" stroke={1.5} />}
              onClick={() => openPageTab("/joyMessages/productConsult")}
              childrenOffset={28}
            />
          </RenderIf>
          <RenderIf auth="HealthConsult">
            <NavLink
              label="健康咨询"
              leftSection={<IconStethoscope size="1rem" stroke={1.5} />}
              onClick={() => openPageTab("/joyMessages/healthConsult")}
              childrenOffset={28}
            />
          </RenderIf>
          <RenderIf auth="OperatingDataView">
            <NavLink
              label="运营数据"
              leftSection={<IconFileDatabase size="1rem" stroke={1.5} />}
              childrenOffset={28}
            >
              <NavLink
                label="数据导出"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/excel/panel")}
                childrenOffset={28}
              />
              <NavLink
                label="全局数据"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/global/data")}
                childrenOffset={28}
              />
              <NavLink
                label="合营随单收益"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/manager/gain")}
                childrenOffset={28}
              />
            </NavLink>
          </RenderIf>
          <RenderIf auth="SystemSettings">
            <NavLink
              label="系统设置"
              leftSection={<IconSettings size="1rem" stroke={1.5} />}
              childrenOffset={28}
            >
              <NavLink
                label="添加初始店铺"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/initAuShops")}
                childrenOffset={28}
              />

              <NavLink
                label="字典维护"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/dictionary/maintainence")}
                childrenOffset={28}
              />
              <NavLink
                label="产品分类维护"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/productCategory/maintainence")}
                childrenOffset={28}
              />

              <NavLink
                label="快递公司维护"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/deliveryVendor/maintainence")}
                childrenOffset={28}
              />
              <NavLink
                label="协议管理"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/protocols")}
                childrenOffset={28}
              />
            </NavLink>
          </RenderIf>

          <When condition={showDebugMenu}>
            <NavLink
              label="开发中调试"
              leftSection={<IconBugOff size="1rem" stroke={1.5} />}
              childrenOffset={28}
            >
              <NavLink
                label="用户关系图"
                leftSection={<IconMenuDeep size="1rem" stroke={1.5} />}
                onClick={() => openPageTab("/debug/users")}
                childrenOffset={28}
              />
            </NavLink>
          </When>
        </div>
        <Alert variant="white" radius={16} title="提示">
          <Text>用心服务，成就非凡</Text>
        </Alert>
      </Stack>
    </AppShell.Navbar>
  );
}

export default WithwingsNavbar;
